const { spawn } = require('child_process');

// 数据库服务
const javaService_datasource = spawn('java', ['-jar', 'assets/java/fas-datasource-1.0-SNAPSHOT.jar']);
// 采集服务
const javaService_dc = spawn('java', ['-jar', 'assets/java/fas-dc-1.0-SNAPSHOT.jar']);

// 监听 Java 服务的标准输出和错误输出
javaService_datasource.stdout.on('data', (data) => {
  console.log(`Java Service stdout: ${data}`);
});

javaService_datasource.stderr.on('data', (data) => {
  console.error(`Java Service stderr: ${data}`);
});

javaService_datasource.on('close', (code) => {
  console.log(`Java Service exited with code ${code}`);
});


// 监听 Java 服务的标准输出和错误输出
javaService_dc.stdout.on('data', (data) => {
  console.log(`Java Service stdout: ${data}`);
});

javaService_dc.stderr.on('data', (data) => {
  console.error(`Java Service stderr: ${data}`);
});

javaService_dc.on('close', (code) => {
  console.log(`Java Service exited with code ${code}`);
});



module.exports = {}


// close
const { app } = require('electron');

// 监听 Electron 应用程序关闭事件
app.on('before-quit', () => {
  // 终止 Java 服务
  javaService_datasource.kill();
  javaService_dc.kill();
});